package com.java.frontweb.controller;

import com.java.base.service.RedisService;
import com.java.frontweb.service.ItemService;
import com.java.frontweb.service.impl.ItemServiceImpl;
import com.java.manage.service.impl.TbItemParamItemServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @ClassName ItemCacheController
 * @Description 前台缓存更新
 * @Author Trigger Wu
 * @Date 2018/9/1416:19
 * @Version 1.0
 **/
@Controller
@RequestMapping("/rest/item/cache")
public class ItemCacheController {
    @Autowired
    private RedisService redisService;
    @Autowired
    private ItemServiceImpl itemService;
    /*
     *  接受商品Id，删除缓存数据
     *
     * @author Tigger Wu
     * @date 2018/9/18 14:19
     * @param [itemId]
     * @return ResponseEntity<Void>
     */
    @RequestMapping(value = "{itemId}", method = RequestMethod.POST)
    public ResponseEntity<Void> deleteCache(@PathVariable("itemId") Long itemId) {
        try {
            String key =itemService.REDIS_KEY+itemId;
            this.redisService.del(key);
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
